<template>
  <div class="default-main ba-table-box">
    <div class="block">
      <div class="table-block">
        <el-alert class="ba-table-alert"
                  v-if="baTable.table.remark"
                  :title="baTable.table.remark"
                  type="info"
                  show-icon />
        <!-- 表格顶部菜单 -->
        <TableHeader :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
                     :quick-search-placeholder="t('Quick search placeholder', { fields: '订单号' })">
          <template #shop>
            <el-select filterable
                       v-model="baTable.comSearch.form['shop_id']"
                       clearable>
              <el-option v-for="item in shop_arr"
                         :key="item.shop_id"
                         :label="item.shop_name"
                         :value="item.shop_id">
              </el-option>
            </el-select>
          </template>
          <template #orderId>
            <el-input v-model="baTable.comSearch.form['order_id']"
                      :rows="2"
                      type="textarea"
                      placeholder="请输入订单号" />
          </template>
        </TableHeader>
        <Table show-overflow-tooltip></Table>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, provide, onBeforeMount } from 'vue'
import baTableClass from '/@/utils/baTable'
// import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { baTableApi } from '/@/api/common'
import Cookies from 'js-cookie'
import { useI18n } from 'vue-i18n'
import { getShopList } from '/@/api/backend/common'

defineOptions({
    name: 'customer/conversations',
})
const { t } = useI18n()
const state: {
    buttonLoading: boolean
} = reactive({
    buttonLoading: false
})
const shop_arr = ref([] as any[])
const baTable = new baTableClass(
    new baTableApi('/customer/conversations/'),
    {
        column: [
            {
                label: '店铺',
                prop:  'shop_id',
                operator: 'LIKE', 
                comSearchRender:'slot',
                comSearchSlotName: 'shop',
                show: false
            },
            {   
                label: '店铺', 
                prop: 'shop_name', 
                align: 'center',
                operator: false,
                width: 150
            },
            {
                label: '订单号',
                prop:  'order_id',
                operator: 'LIKE', 
                comSearchRender:'slot',
                comSearchSlotName: 'orderId',
                width: 170
            },
            {   
                label: '发送者', 
                prop: 'sender_nickname', 
                align: 'center',
                operator: false,
                width: 150
            },
            {   
                label: '消息内容', 
                prop: 'content', 
                align: 'center',
                operator: false
            },
            {   
                label: '角色', 
                prop: 'sender_role', 
                align: 'center',
                render: 'tag',
                replaceValue: { 
                    'BUYER': '买家',
                    'SYSTEM': '系统',
                    'CUSTOMER_SERVICE': '客服',
                    'ROBOT': '机器人'
                },
                width: 100
            },
            { 
                label: '头像', 
                prop: 'sender_avatar', 
                align: 'center', 
                render: 'image', 
                operator: false,
                width: 100
            },
            {   
                label: '消息类型', 
                prop: 'message_type', 
                align: 'center',
                render: 'tag',
                operator: false,
                width: 120
            },
            {   
                label: '创建时间', 
                prop: 'createtime', 
                align: 'center',
                render: 'datetime',
                operator: false,
                width: 160
            }
        ],
        dblClickNotEditColumn: ['all']
    },
    {
        defaultItems: {
            status: '1',
        }
    }
)

provide('baTable', baTable)

baTable.mount()
baTable.getIndex()
const getShopArr = () => {
    getShopList().then(res => {
        if(res.data && res.data.list.length) {
            shop_arr.value = res.data.list
        }
    })
}

onBeforeMount(() => {
    getShopArr()
})
</script>

<style scoped lang="scss">
:deep(.el-popper.is-dark) {
    max-width: 50%;
}
</style>
